package com.lishangshan.oas_system.controller.menu;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 菜单管理 控制 层
 */
@Controller
@RequestMapping("/")
public class MenuController {
   /* @Autowired
    private SystemMenuDao menuDao;

    *//**
     * 初始化 菜单 管理 列表
     *
     * @param page
     * @return
     *//*
    @RequestMapping("/testsysmenu")
    public ModelAndView findAllForFu(@RequestParam(value = "page", defaultValue = ParameterUtil.PAGE_NUMBER) Integer page
            , @RequestParam(value = "mid", defaultValue = ParameterUtil.PAGE_NUMBER) Long mid, HttpServletRequest request*//*@RequestParam(value = "parent", defaultValue = ParameterUtil.PAGE_NUMBER) Integer parent*//*
    ) {
        request.getSession().removeAttribute("mid");
        Pageable pa = new PageRequest(page, ParameterUtil.PAGE_SIZE_MAX);
        ModelAndView mav = new ModelAndView("menu/menumanage");
        // 如果 parent 为 0 则 查找 父级菜单
        *//*      if (mid == 0) {*//*
        Page<SystemMenu> systemMenus = menuDao.findAllByFu(mid, pa);
        List<SystemMenu> menulist = systemMenus.getContent();
        System.out.println("菜单数据 ：" + menulist);
        mav.addObject("page", systemMenus);
        mav.addObject("menulist", menulist);
        //存储 session 值 做于 父级菜单id对应 查询 子菜单
        request.getSession().setAttribute("mid", mid);
        mav.addObject("url", "menuser");
        return mav;
        // 如果 不为 0 则 查找  子级 菜单
        *//*} else if (mid != 0) {
            Page<SystemMenu> systemMenus = menuDao.findAllByZi(mid, pa);
            List<SystemMenu> menulist = systemMenus.getContent();
            System.out.println("子级菜单数据 ：" + menulist);
            mav.addObject("page", systemMenus);
            mav.addObject("menulist", menulist);
            mav.addObject("url", "menuser");
//            mav.addObject("mid", mid);
            request.getSession().setAttribute("mid", mid);
            return mav;
        }*//*
    }

    *//**
     * 分页数据处理 ，以及 搜索框 搜索
     *
     * @param page
     * @param model
     * @param req
     * @return
     *//*
    @RequestMapping("/menuser")
    public String menuser(@RequestParam(value = "page", defaultValue = ParameterUtil.PAGE_NUMBER) Integer page,
                          Model model, HttpServletRequest req
            *//*@RequestParam(value = "parent", defaultValue = ParameterUtil.PAGE_NUMBER) Integer parent*//*) {
        System.out.println("page = " + page);
        Long mid = (Long) req.getSession().getAttribute("mid");
        System.out.println("mid = " + mid);
        Pageable pa = new PageRequest(page, ParameterUtil.PAGE_SIZE_MAX);
        Page<SystemMenu> systemMenus = null;
        List<SystemMenu> menulist = null;
        String val = null;
        // val 判断 val 是否为空
        if (!StringUtil.isEmpty(req.getParameter("val"))) {
            val = req.getParameter("val").trim();

        }
        // val 不为 空时 查找 信息
        if (!StringUtil.isEmpty(val)) {
            // 搜索框  搜索时
            systemMenus = menuDao.findByMuneName(val, pa);
            model.addAttribute("sort", "&val=" + val);
        } else {
            // 分页 点击 时
            *//*    if (mid != 0) {*//*
            systemMenus = menuDao.findAllByZi(mid, pa);
          *//*  } else {
                systemMenus = menuDao.findAllByFu(0l, pa);
            }*//*
        }

        menulist = systemMenus.getContent();
        // 开始 传参
        System.out.println("菜单数据 ：" + menulist);
        model.addAttribute("page", systemMenus);
        model.addAttribute("menulist", menulist);
        model.addAttribute("url", "menuser");
        return "menu/menutable";
    }

    *//**
     * 上下移动菜单操作
     *
     * @param id
     * @param sortId
     * @return
     *//*
    //upmenu
    @RequestMapping("movemenu")
    public String upmenu(@RequestParam("id") Long id, @RequestParam("sortId") int sortId, @RequestParam("flag") String flag, Model model, HttpServletRequest req) {
        if ("up".equals(flag)) {
            sortId--;
        } else {
            sortId++;
        }
        if (sortId > 0) {
            try {
                // 调用上移方法
                menuDao.upmenu(id, sortId);
                System.out.println("移动成功");
                *//*model.addAttribute("success", "上移成功刷新页面看效果");*//*
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            model.addAttribute("errormess", "已经是最上层无法上移");
        }
        Long mid = (Long) req.getSession().getAttribute("mid");
        return "forward:/testsysmenu?mid=" + mid + "";
    }*/
}
